<?php

class Storage {
	function factory(String $type,Context &$context){
		$classname = $type.'_StorageDriver';
		if(ls_load(LIBRAR_DIR."/lslib/${$classname}.php")){
			return new $classname($context);
		}else{
			return new StorageException("Storage Driver '$type' Not Found");
		}
	}
}

class Base_StorageDriver{
	
	var $context;
	function Base_StorageDriver(&$context){
		$this->context = &$context;
	}

	function query(&$sql){
		
	}
	
	function execute(&$sql){
		
	}
}

class Base_StroageDriver_RecordSet{
	
	var $RowCount ;
	var $FieldCount ;
	var $Row ;
	var $Field;
	var $RowIndex;
	var $FetchIndex;
	
	function Base_StorageDriver_RecordSet(){
		
	}
	
	function hasNext(){
		return ($this->RowIndex<$this->RowCount);
	}
	
	function hasPrevious(){
		return ($this->RowIndex>0);
	}
	
	function next(){
		if($this->hasNext())
		$RowIndex ++;
	}
	
	function previous(){
		if($this->hasPrevious())
		$RowIndex --;
	}
	
}


class StorageError extends Error {
    function StorageError(String $message,int $code = 0) {
        parent::Error($message, $code);
    }

    function __toString() {
        return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
    }
}

?>